package com.ycwl.freetv.program;

import android.content.Context;
import android.os.Environment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.ycwl.library.ParseUIFromJson;

import java.io.File;

public class Image implements ProgramInterface {
    ImageView view;
    final Context context;
    final ParseUIFromJson.BaseNode baseNode;
    public Image(Context context, ParseUIFromJson.BaseNode baseNode) {
        this.context = context;
        this.baseNode = baseNode;
        ImageView imageView = new ImageView(context);
        ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(960, 540);
        marginLayoutParams.leftMargin = baseNode.x.intValue();
        marginLayoutParams.topMargin = baseNode.y.intValue();
        marginLayoutParams.width = baseNode.width.intValue();
        marginLayoutParams.height = baseNode.height.intValue();
        imageView.setLayoutParams(marginLayoutParams);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        this.view = imageView;
    }

    @Override
    public void play() {
        File file = new File(baseNode.url); // 替换为你的图片文件路径
        Glide.with(context)
                .load(file)
                .into(this.view);
    }

    @Override
    public void stop() {

    }

    @Override
    public void setTotalTime(int totalTime) {

    }

    @Override
    public void pause() {

    }

    @Override
    public View getView() {
        return this.view;
    }
}
